package util
{
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import org.flixel.FlxG;
	import org.flixel.FlxText;
	
	public class DynamicText extends FlxText
	{
		
		private var dieTimer:Timer;
		
		public function DynamicText(x:Number,y:Number,width:uint,text:String,_size:int) 
		{
			super(x, y, width, text);
			size = _size;
			color = 0xffffffff; 	
			//add text to the current stateaaaaa
			FlxG.state.add(this);
		}
		
		
		
		public function fadeAndDie(time:int)
		{
			//fade the text
			dieTimer = new Timer(time, 5);
			dieTimer.addEventListener(TimerEvent.TIMER, fadeText);
			dieTimer.addEventListener(TimerEvent.TIMER_COMPLETE, dieText);
			dieTimer.start();
		}
		
		private function dieText(e:TimerEvent):void 
		{
			dieTimer.removeEventListener(TimerEvent.TIMER, fadeText);
			dieTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, dieText);	
			FlxG.state.remove(this);
		}
		
		private function fadeText(e:Event):void 
		{
			this.alpha = this.alpha -.2;
		}
		
		
	}

}